package com.wesley.netty.jvm;

import org.openjdk.jol.info.ClassLayout;

/**
 * JOLSample
 *
 * @author WangPanYong
 * @since 2021/06/10 14:09
 */
public class JOLSample {

    public static void main(String[] args) {
        ClassLayout layout = ClassLayout.parseInstance(new Object());
        System.out.println(layout.toPrintable());

        System.out.println("----------------\r\n");

        ClassLayout layout1 = ClassLayout.parseInstance(new int[]{});
        System.out.println(layout1.toPrintable());

        System.out.println("----------------\r\n");

        ClassLayout layout2 = ClassLayout.parseInstance(new A());
        System.out.println(layout2.toPrintable());
    }

    /**
     * -XX:+UseCompressedOops JDK8默认开启的压缩所有指针
     * -XX:-UseCompressedOops 禁止指针压缩
     */
    static class A {

        // 8 byte
        long id;

        // 4 byte
        int age;

        // 4 byte 如果关闭压缩-XX:-UseCompressedOops，则占用8byte
        String name;

        // 1 byte
        byte sex;

        // 4 byte 如果关闭压缩-XX:-UseCompressedOops，则占用8byte
        Object obj;
    }
}
